package my.convert.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import my.convert.attribute.processor.AttributeProcessor;
import my.convert.attribute.processor.impl.ArrayTypeAttributeProcessor;
import my.convert.attribute.processor.impl.BasicTypeAttributeProcessor;
import my.convert.attribute.processor.impl.ListTypeAttributeProcessor;
import my.convert.attribute.processor.impl.MapTypeAttributeProcessor;
import my.convert.attribute.processor.impl.OtherReferenceTypeAttributeProcessor;
/**
 * 
 * @author xuanhu
 *
 */
public abstract class AbstractEntityAnalyzer {
	
	protected List<AttributeProcessor> attributeProcessors = new ArrayList<AttributeProcessor>();
	protected Map<Class<?>,Map<String,Class<?>>> entityKeyMapper = new HashMap<Class<?>,Map<String,Class<?>>>();
	
	public AbstractEntityAnalyzer() {
		super();
		attributeProcessors.add(new ArrayTypeAttributeProcessor());
		attributeProcessors.add(new BasicTypeAttributeProcessor());
		attributeProcessors.add(new MapTypeAttributeProcessor());
		attributeProcessors.add(new ListTypeAttributeProcessor());
		attributeProcessors.add(new OtherReferenceTypeAttributeProcessor());
	}
	public  Map<String,Class<?>> getEntityKeyMapper(Class<?> entityClass){
		if(this.entityKeyMapper.get(entityClass)==null) {
			HashMap<String, Class<?>> mapper = new HashMap<String,Class<?>>();
			this.analyzerAttribute(entityClass, mapper);
			if(mapper!=null)this.entityKeyMapper.put(entityClass, mapper);
			mapper=null;
		}
		return this.entityKeyMapper.get(entityClass);
	}
	protected abstract void analyzerAttribute(Class<?> entityClass,Map<String,Class<?>> mapper);
}
